package com.hcbd.tdwt.ui.setting.xingyu.activity;

import android.annotation.SuppressLint;
import android.widget.Button;
import android.widget.EditText;

import com.hcbd.tdwt.R;
import com.hcbd.tdwt.base.BaseActivity;

import com.pangu.bdsdk2021.entity.extensionterminal.BDYPXInfo;
import com.pangu.bdsdk2021.entity.extensionterminal.CCYPSInfo;
import com.pangu.bdsdk2021.terminal.TerminalSendManager;


import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

@SuppressLint("NonConstantResourceId")
@EActivity(R.layout.activity_work_agree)
public class WorkAgreeActivity extends BaseActivity {
    @ViewById
    EditText rdssET,rnssET,operateEt;
    @ViewById
    Button implementBtn;
    private CCYPSInfo ccypsInfo;
    @AfterViews
    protected void init() {
        initMsgRegister();
        inquire();
    }


    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true, priority = 1)
    public void eventBus(BDYPXInfo bdypxInfo){
        rdssET.setText(bdypxInfo.RDSSProtocol);
        rnssET.setText(bdypxInfo.RNSSProtocol);
        toast("加载成功！");
    }
    @Click
    void implementBtn(){
        String operate=getTextStr(operateEt);
        if("".equals(operate)||(!"1".equals(operate)&&!"0".equals(operate))){
            toast("请输入正确操作值");
            return;
        }
        if("0".equals(operate)){
            inquire();
            return;
        }
        String rdss=getTextStr(rdssET);
        if("".equals(rdss)||(!"1".equals(rdss)&&!"0".equals(rdss))){
            toast("请输入正确RDSS操作值");
            return;
        }
        String rnss=getTextStr(rnssET);
        if("".equals(rnss)||(!"1".equals(rnss)&&!"0".equals(rnss))){
            toast("请输入正确RNSS操作值");
            return;
        }
        ccypsInfo.instruction=Integer.parseInt(operate);
        ccypsInfo.RDSSProtocol=rdss;
        ccypsInfo.RNSSProtocol=rnss;
        TerminalSendManager.getInstance().level_two_setCCYPS(ccypsInfo);
        toast("已发送！");
    }
    public void inquire(){
        ccypsInfo=new CCYPSInfo();
        ccypsInfo.instruction=0;//0读取参数 1 设置参数
        TerminalSendManager.getInstance().level_two_setCCYPS(ccypsInfo);
    }
    @Click
    void headLeft(){
        finish();
    }
}
